from django.test import TestCase
import os
import django
from 学术 import settings
#from user.models import *
from elasticsearch import Elasticsearch
import os

if __name__ == '__main__':
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "学术.settings") #文件内容在自己项目的wsgi.py文件中第14行
    import django
    django.setup()
    from search.models import *


    es = Elasticsearch(['127.0.0.1:9200'])
    rres = es.search(index='sciencesaki', size=1,body={
            "query": {
                "match": {
                    "publish_year": '2001'
            }
        }
    })
    print(rres)
    res=[]
    r = rres['hits']['hits']
    print(len(r))

    for i in range(len(r)):
        res.append(r[i]['_source']['text'].split("\n"))
    print(res)
# Create your tests here.
